package com.gui;

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import com.QuranParser;

import com.dataModel.Quran;

public class CopyOfMainFrame extends JFrame implements KeyListener{
	
	JTextArea jta=new JTextArea();
	String ayah;
	int counter=0;
	public CopyOfMainFrame()
	{
		super.setTitle("My Quran");
		super.setSize(500, 600);
		super.getContentPane().add(new JScrollPane(jta));
		for(Font f:GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts())
		{
			//System.out.println(f.getFamily());
		} 
		int l=GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts().length;
		System.out.println("font length="+l);
		Font font=new Font("Arial Bold",1,20);
		jta.setFont(font);
		load();
		jta.addKeyListener(this);
		super.setVisible(true);
		
	}
	void load()
	{
		File file=new File("data/quran.ar.xml");
		StringBuffer result=new StringBuffer();
		try {
			BufferedReader allData8 = new BufferedReader(new InputStreamReader
					(new FileInputStream(new File( "data/quran.ar.xml")),"UTF8"));
			
			
			FileInputStream in=	new FileInputStream(file);
			int read;
			int charNb=0;
			while ((read=allData8.read())!=-1)
			{charNb++;
				result.append((char)read);
			}
			ayah=result.toString();
      System.out.println(ayah.contains("WwdEmbedded"));
      System.out.println(ayah.length());
        //jta.setText(ElNass());
			jta.setText(ayah.substring(1000, 20000));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	String ElNass()
	{
		String elNass="";
		Quran quran=QuranParser.getQuran();
		
		for(int i=0;i<quran.getSowar()[113].getAyat().size();i++)
		{
			elNass+=quran.getSowar()[113].getAyat().get(i).getTextMoshakal();
		}
		
		return elNass;
		
	}
	public void keyPressed(KeyEvent arg0) {

		Font font=GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()[counter];
		
		System.out.println(counter+" "+font.getName());
				counter++;
				
				jta.setFont(new Font(font.getName(),1,50));
			
				jta.setText(ayah);
				jta.updateUI();
		
	}
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
		
	}

}
